<template>
  <div>
    <p>支付宝账号：{{ ali.ali_count }}</p>
    <p>支付宝授权PID：{{ ali.ali_pid }}</p>
    <p>商家结算周期：{{ ali.balance_type }}</p>
    <p>通道类型：{{ ali.channel_type === 0 ? '普通' : ali.channel_type === 1 ? '蓝海行动' : ali.channel_type === 2 ? '公益类': '无' }}</p>
    <p>当前执行费率：{{ ali.rate }}%</p>
    <p v-if="ali.channel_type !== 2">到期时间：{{ ali.expire_time }}</p>
    <p v-if="ali.expire_time">到期执行费率：{{ ali.expire_rate }}%</p>
    <el-row>
      <el-col :span="23" :offset="1">
        <el-button type="primary" size="small" @click="handleClickOnSubmit(200)">通过</el-button>
        <el-button type="danger" size="small" @click="handleClickOnSubmit(-200)">不通过</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { merchantChannelAliQuery, verfiryChannelAliValid } from '@/api/shop'

export default {
  name: 'AuditAliChannel',
  data() {
    return {
      ali: {
        ali_pid: '',
        ali_count: '',
        balance_type: '',
        rate: '',
        expire_time: '',
        expire_rate: '',
        channel_type: null
      }
    }
  },
  methods: {
    handleDocumentInit() {
      merchantChannelAliQuery(this.$route.query.id).then(res => {
        if (res.data.errorCode === 0) {
          this.ali.ali_count = res.data.result.ali_count
          this.ali.ali_pid = res.data.result.ali_pid
          this.ali.balance_type = res.data.result.balance_type
          this.ali.channel_type = res.data.result.channel_type
          this.ali.expire_rate = Number(res.data.result.expire_rate)
          this.ali.expire_time = res.data.result.expire_time
          this.ali.rate = Number(res.data.result.rate)
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    },
    handleClickOnSubmit(status) {
      if (status === -200) {
        this.$msgbox({
          title: '拒绝原因',
          showInput: true,
          inputType: 'textarea',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: true
        }).then(({ value }) => {
          verfiryChannelAliValid(this.$route.query.id, status, value).then(res => {
            if (res.data.errorCode === 0) {
              this.$message.success(res.data.errorMsg)
              this.$emit('update')
            } else {
              this.$message.error(res.data.errorMsg)
            }
          })
        }).catch(() => {
          return false
        })
      } else {
        verfiryChannelAliValid(this.$route.query.id, status, '').then(res => {
          if (res.data.errorCode === 0) {
            this.$message.success(res.data.errorMsg)
            this.$emit('update')
          } else {
            this.$message.error(res.data.errorMsg)
          }
        })
      }
    }
  },
  created() {
    this.handleDocumentInit()
  }
}
</script>
